package com.yulongtian.oneProblemEveryDay.month202303;

import java.util.HashMap;

/**
 * https://leetcode.cn/problems/triples-with-bitwise-and-equal-to-zero/
 *
 * @author yulongTian
 * @create 2023-03-04 9:14
 */
public class Test03 {
    public static void main(String[] args) {
        System.out.println(countTriplets(new int[]{2,1,3,2}));
    }

    public static int countTriplets(int[] nums) {
        int[] cnt = new int[1<<16];
        for(int x:nums){
            for(int y:nums){
                cnt[x&y]++;
            }
        }
        int res = 0;
        for(int i:nums){
            for(int t=0;t<(1<<16);t++){
                if((i&t)==0){
                    res+=cnt[t];
                }
            }
        }
        return res;
    }

//    //超时   25/25
//    public static int countTriplets(int[] nums) {
//        int ans = 0;
//
//        for (int i = 0; i < nums.length; i++) {
//            for (int j = 0; j < nums.length; j++) {
//                for (int k = 0; k < nums.length; k++) {
//                    if ((nums[i] & nums[j] & nums[k]) == 0) {
//                        System.out.println(i + "," + j + "," + k);
//                        ans++;
//                    }
//                }
//            }
//        }
//        return ans;
//    }
}
